<?php
    if(isset($_POST['contact'])){
        $contact = $_POST['contact'];
        $success = true;
        unset($_POST['contact']);
    }
?>
<?php get_header() ?>
<?php
$option = get_option('tvpresident_1_settings');
?>
<?php
    if(isset($contact)){
        $html = '================================<br/>';
        $html.='<b><u>Your Name:</u></b> '.$contact['name'].'<br/>';
        $html.='<b><u>E-mail address:</u></b> '.$contact['email'].'<br/>';
        $html.='<b><u>Phone Number:</u></b> '.$contact['phone'].'<br/>';
        $html.='<b><u>Title:</u></b> '.$contact['title'].'<br/>';
        $html.='<b><u>Content:</u></b> '.$contact['content'].'<br/>';
        $html.= '================================';
        $current_site = get_bloginfo('name');
        add_filter( 'wp_mail_content_type', 'set_html_content_type' );
        wp_mail($option['email_contact'], 'Contact to us - '.$current_site, $html);
        remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
    }
?>
<script type="text/javascript">
    function check_media(){
        var required = $('#mediaform .required');
        for(var i=0;i<required.length;i++){
            var each = required[i];
             if($(each).val()==''){
                alert('Please fill '+$(each).attr('data')+'!');
                $(each).focus();
                return false;
            }
        }
    }
</script>
<div id="content">
        <div class="ngangborder"></div>
        <div class="left-content">
          
          <div style="clear:both"></div>
          <div class="divlist">
            <?php
            wp_reset_query();
            if (have_posts())
            while (have_posts()) : the_post();
                ?>
                 <div class="divtitle"><?php the_title() ?></div>
                  <div class="ngangborder"></div>
                  <div class="divcontent page">
                      <?php the_content() ?>
            <?php endwhile; ?>
                    <form id="mediaform"  method="post" onsubmit="return check_media()">
                        <h4 class="strong"><font><font class="">○ Contact to us (required item ※) - Give us the form below</font></font></h4>
                        
                        <!-- text -->
                        <div><font><font>* Your Name (required)</font></font><br>
                        <input data="your name" class="required" name="contact[name]" type="text" size="30">
                        </div>
                        <!-- text:mail -->
                        <div><font><font>* E-mail address (required)</font></font><br>
                        <input data="e-mail address" class="required" name="contact[email]" type="text" size="30">
                        </div>
                        <!-- tel3 -->
                        <div><font><font>Phone Number (Optional)</font></font><br>
                        <input name="contact[phone]" type="text" size="30">
                        </div>
                        <!-- text -->
                        <div><font><font>* Title (required)</font></font><br>
                        <input data="title" class="required" name="contact[title]" type="text" size="30">
                        </div>
                        <!-- textarea -->
                        <div><font><font>* Content (required)</font></font><br>
                        <textarea data="content" class="required" name="contact[content]" cols="50" rows="10"></textarea>
                        </div>
                        <div style="color:green;padding: 5px;"><?php if(isset($success)){ ?> Sent contact successful!<?php } ?></div>
                        <!-- charset -->
                        <div class="submit"><font><font><input class=" button black medium buttonsearch"  name="submit" type="submit" value="Send"></font></font></div>
                        <br/>
                    </form>
                  </div>
          </div>
         
        </div>
        <div class="right-content">
          <?php get_sidebar() ?>
        </div>
        <div style="clear:both"></div>
      </div>
      <div style="clear:both;"></div>
<?php get_footer() ?>